/*
 * Created by JFormDesigner on Sun May 22 22:57:16 CST 2022
 */

package jw3.c2.view;

import jw3.c2.controller.AdministratorController;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author Brainrain
 */
public class Login1 extends JFrame {
    public Login1() {
        initComponents();
        setLocation(500,300);
        setSize(800,600);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
    }

    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        String user=textField1.getText();
        String Phone=textField2.getText();
        String pwd=new String(passwordField1.getPassword());
        String pwd1=new String(passwordField2.getPassword());
        if (!user.equals("") && !Phone.equals("")){
            if (AdministratorController.login1(user,Phone)){
                if (!pwd.equals("")&& !pwd1.equals("")){
                    if (pwd.equals(pwd1)){
                        AdministratorController.login2(pwd,user,Phone);
                            JOptionPane.showMessageDialog(null, "验证成功！");
                    }else {
                        JOptionPane.showMessageDialog(null,"密码和确认密码不相符");
                    }
                }else {
                    JOptionPane.showMessageDialog(null,"密码或确认密码不能为空！");
                }
            }else {
                JOptionPane.showMessageDialog(null,"账号或身份证号错误！");
            }
        }else {
            JOptionPane.showMessageDialog(null,"账号或身份证号不能为空！");
        }
    }

    private void label4MouseClicked(MouseEvent e) {
        // TODO add your code here
        Login l=new Login();
        setVisible(false);
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        textField1 = new JTextField();
        label2 = new JLabel();
        textField2 = new JTextField();
        button1 = new JButton();
        label4 = new JLabel();
        label3 = new JLabel();
        passwordField1 = new JPasswordField();
        label5 = new JLabel();
        passwordField2 = new JPasswordField();
        label6 = new JLabel();

        //======== this ========
        setTitle("\u627e\u56de\u5bc6\u7801");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);

        //---- label1 ----
        label1.setText("\u8d26\u53f7\uff1a");
        contentPane.add(label1);
        label1.setBounds(new Rectangle(new Point(315, 157), label1.getPreferredSize()));
        contentPane.add(textField1);
        textField1.setBounds(380, 150, 140, 30);

        //---- label2 ----
        label2.setText("\u8eab\u4efd\u8bc1\u53f7\uff1a");
        contentPane.add(label2);
        label2.setBounds(new Rectangle(new Point(303, 205), label2.getPreferredSize()));
        contentPane.add(textField2);
        textField2.setBounds(380, 205, 140, 30);

        //---- button1 ----
        button1.setText("\u9a8c\u8bc1");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(410, 400), button1.getPreferredSize()));

        //---- label4 ----
        label4.setText("\u8fd4\u56de\u767b\u5f55");
        label4.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                label4MouseClicked(e);
            }
        });
        contentPane.add(label4);
        label4.setBounds(new Rectangle(new Point(520, 407), label4.getPreferredSize()));

        //---- label3 ----
        label3.setText("\u5bc6\u7801\uff1a");
        contentPane.add(label3);
        label3.setBounds(new Rectangle(new Point(315, 262), label3.getPreferredSize()));
        contentPane.add(passwordField1);
        passwordField1.setBounds(380, 255, 140, 30);

        //---- label5 ----
        label5.setText("\u786e\u8ba4\u5bc6\u7801\uff1a");
        contentPane.add(label5);
        label5.setBounds(new Rectangle(new Point(303, 327), label5.getPreferredSize()));
        contentPane.add(passwordField2);
        passwordField2.setBounds(380, 320, 140, 30);

        //---- label6 ----
        label6.setText("text");
        label6.setIcon(new ImageIcon("C:\\Users\\\u5c0f\u6797\\Desktop\\L.jpg"));
        contentPane.add(label6);
        label6.setBounds(new Rectangle(new Point(0, -15), label6.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
        setSize(400,300);

    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JTextField textField1;
    private JLabel label2;
    private JTextField textField2;
    private JButton button1;
    private JLabel label4;
    private JLabel label3;
    private JPasswordField passwordField1;
    private JLabel label5;
    private JPasswordField passwordField2;
    private JLabel label6;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
